package com.project.server.estates;

import java.util.List;

import com.project.common.core.page.TableDataInfo;
import com.project.server.domain.estates.TEstatesTask;
import com.project.server.service.estates.ITEstatesTaskService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.enums.BusinessType;
import com.project.common.utils.poi.ExcelUtil;

import javax.annotation.Resource;

/**
 * 物业管理运维任务Controller
 *
 * @author project
 * @date 2021-06-28
 */
@RestController
@RequestMapping("/server/task")
public class TEstatesTaskController extends BaseController {

    @Resource
    private ITEstatesTaskService tEstatesTaskService;

    /**
     * 查询物业管理运维任务列表
     */
    @PreAuthorize("@ss.hasPermi('server:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(TEstatesTask tEstatesTask){
        startPage();
        List<TEstatesTask> list = tEstatesTaskService.selectTEstatesTaskList(tEstatesTask);
        return getDataTable(list);
    }

    /**
     * 导出物业管理运维任务列表
     */
    @PreAuthorize("@ss.hasPermi('server:task:export')")
    @Log(title = "物业管理运维任务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TEstatesTask tEstatesTask) {
        List<TEstatesTask> list = tEstatesTaskService.selectTEstatesTaskList(tEstatesTask);
        ExcelUtil<TEstatesTask> util = new ExcelUtil<TEstatesTask>(TEstatesTask.class);
        return util.exportExcel(list, "物业运维任务列表");
    }

    /**
     * 获取物业管理运维任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:task:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId) {
        return AjaxResult.success(tEstatesTaskService.selectTEstatesTaskById(taskId));
    }

    /**
     * 新增物业管理运维任务
     */
    @PreAuthorize("@ss.hasPermi('server:task:add')")
    @Log(title = "物业管理运维任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TEstatesTask tEstatesTask) {
        return toAjax(tEstatesTaskService.insertTEstatesTask(tEstatesTask));
    }

    /**
     * 修改物业管理运维任务
     */
    @PreAuthorize("@ss.hasPermi('server:task:edit')")
    @Log(title = "物业管理运维任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TEstatesTask tEstatesTask) {
        return toAjax(tEstatesTaskService.updateTEstatesTask(tEstatesTask));
    }

    /**
     * 删除物业管理运维任务
     */
    @PreAuthorize("@ss.hasPermi('server:task:remove')")
    @Log(title = "物业管理运维任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds) {
        return toAjax(tEstatesTaskService.deleteTEstatesTaskByIds(taskIds));
    }
}
